package admin.staff.dao;

import java.util.List;

import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Component;

import com.hakgwa.domain.HakgwaCommand;
import com.staff.domain.StaffCommand;

@Component
public class StaffDaoImpl extends SqlSessionDaoSupport implements StaffDao{

	@Override
	public List<StaffCommand> getMemberList() {
		List<StaffCommand> list = getSqlSession().selectList("getStaffList");
		return list;
	}

	@Override
	public int getMemberCount() {

		return 0;
	}

	@Override
	public void insertMember(StaffCommand staffCommand) {
		getSqlSession().insert("insertStaff",staffCommand);
		
	}

	@Override
	public StaffCommand getMember(String id) {
		StaffCommand staffCommand = getSqlSession().selectOne("getStaff",id);
		return staffCommand;

	}

	@Override
	public void updateMember(StaffCommand member) {
		getSqlSession().update("updateStaff",member);
	}

	@Override
	public void deleteStaff(List<String> idList) {
		SqlSessionFactory sqlSessionFactory =new SqlSessionFactoryBuilder().build(getSqlSession().getConfiguration());
		SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH);
		try{
			for(String id:idList){
				session.delete("deleteStaff",id);
			}
			session.commit();
		}catch(Exception e){
			e.printStackTrace();
			session.rollback();
		}finally{
			session.close();
			
		}
		
		
	}

	
	
	@Override
	public List<StaffCommand> getGyosulist(String gwa_code) {
		List<StaffCommand> list = getSqlSession().selectList("getGyosulist", gwa_code);
		
		return list;
	}

	@Override
	public List<HakgwaCommand> getGwalist(String code) {
		List<HakgwaCommand> gwalist = getSqlSession().selectList("getGwalist",code);
		
		return gwalist;
	}


}
